#include "SOC_GX.h"
#include "rtwtypes.h"
#include "SOC_LookUp.h"
#include "LookUp_real32_TU8_U16.h"
#include "SOC_GX_private.h"
#include "look1_is16lftf_binlcapw.h"
#include "plook_u8s16_bincka.h"
#include "calPrms.h"

void SOC_LookUp(boolean_T rtu_Enable, const real32_T rtu_SOC_Compensation[2],
                const uint16_T rtu_CellV_Min_Cal[2], const int16_T
                *rtu_CellT_Min, real32_T rty_Calib_RealSOC[2], real32_T
                rty_Lookup_RealSOC[2], real32_T *rty_SOC_Diff)
{
  int32_T i;
  uint16_T rtb_DirectLookupTablenD[11];
  if (rtu_Enable) {
    int32_T tableOffset;
    real32_T rtb_uDLookupTable1_f;
    uint8_T u0;
    rtb_uDLookupTable1_f = look1_is16lftf_binlcapw(*rtu_CellT_Min, (const
      int16_T *)&Capacity_Keep_CellT[0], (const real32_T *)
      &Capacity_Keep_Factor[0], 8U);
    u0 = plook_u8s16_bincka(*rtu_CellT_Min, (const int16_T *)&CellT_OCV[0], 3U);
    if (u0 > 3) {
      u0 = 3U;
    }

    tableOffset = u0 * 11;
    for (i = 0; i < 11; i++) {
      rtb_DirectLookupTablenD[i] = OCV_Table[i + tableOffset];
    }

    real32_T rtb_Subtract1_i;
    LookUp_real32_TU8_U16( &(rty_Lookup_RealSOC[0]), (const uint8_T *)&OCV_SOC[0],
                          rtu_CellV_Min_Cal[0], &rtb_DirectLookupTablenD[0], 10U);
    LookUp_real32_TU8_U16( &(rty_Lookup_RealSOC[1]), (const uint8_T *)&OCV_SOC[0],
                          rtu_CellV_Min_Cal[1], &rtb_DirectLookupTablenD[0], 10U);
    rtb_Subtract1_i = 100.0F - rtb_uDLookupTable1_f * 100.0F;
    rty_Lookup_RealSOC[0] = rtb_uDLookupTable1_f * rty_Lookup_RealSOC[0] +
      rtb_Subtract1_i;
    rty_Calib_RealSOC[0] = rtu_SOC_Compensation[0] + rty_Lookup_RealSOC[0];
    rty_Lookup_RealSOC[1] = rtb_uDLookupTable1_f * rty_Lookup_RealSOC[1] +
      rtb_Subtract1_i;
    rty_Calib_RealSOC[1] = rtu_SOC_Compensation[1] + rty_Lookup_RealSOC[1];
    *rty_SOC_Diff = rty_Lookup_RealSOC[0] - rty_Lookup_RealSOC[1];
  }
}
